import mysql from 'mysql';
let pool=mysql.createPool(require("./../../config"));

function query(sql,params){
    return new Promise((resolve,reject)=>{
        pool.getConnection((err,conn)=>{
            if(err){
                reject(err)
                //throw err;
            }
            conn.query(sql,params,(err,result,fields)=>{
                conn.release();//释放连接
                if(err){
                    reject(err)
                   // throw err;
                }
                resolve(result)
            })

        })
    })
}


async function queryAsync(){
    return await query(...arguments);

}

// exports.query=query;
// exports.queryAsync=queryAsync;

module.exports={
    query,
    queryAsync
}